﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Serialization;
using System.Windows.Controls;
//using System.Windows.Forms;

namespace QA_System
{
    public class DisplayTreeview
    {


        static public void Display(ref TextBox parent, string iNputString)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(iNputString);
                TreeView tree = new TreeView();
                TreeViewItem root = new TreeViewItem();
                root.Header = "cấu trúc ngữ pháp";
                tree.Items.Add(root);
                //tree.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;                
                //tree.LineColor = System.Drawing.Color.Chocolate;
                tree.Height = parent.Height;
                tree.Width = parent.Width;
                XmlNodeList nodelist = doc.SelectNodes("//s");
                foreach (XmlNode node in nodelist)
                {
                    TreeViewItem treeNode = new TreeViewItem();
                    treeNode.Header = node.Name;
                    root.Items.Add(treeNode);                   
                    
                    foreach (XmlNode child in node.ChildNodes) 
                    {
                        TreeViewItem subNode = new TreeViewItem();
                        subNode.Header = child.Attributes["pos"].Value + " _ " + child.InnerText;
                        treeNode.Items.Add(child);                        
                    }
                }
                root.ExpandSubtree();                

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void CLear(ref TextBox parent, string cntlName)
        {
            parent.Clear();
        }

       
    }
}
